import ajax from "axios";

const modules = {
  namespaced: true,
  state: {
    id: localStorage['id'] ? localStorage['id'] : "",
    isLogin: localStorage['isLogin'] ? Boolean(localStorage['isLogin']) : false,
    username: localStorage['username'] ? localStorage['username'] : "",
    head: localStorage['head'] ? localStorage['head'] : "",
  },
  mutations: {
    saveLogin(state, user) {
      state.id = user.id;
      state.username = user.username;
      state.head = user.head;
      state.isLogin = true;
      localStorage["id"] = user.id;
      localStorage['isLogin'] = true;
      localStorage['username'] = user.username;
      localStorage['head'] = user.head
    },
    outLogin(state) {
      state = {};
      localStorage.removeItem('username')
      localStorage.removeItem("id");
      localStorage.removeItem("isLogin");
      localStorage.removeItem('head')
      sessionStorage.removeItem('token');
      sessionStorage.removeItem('PlayerList')
    },
  },
  actions: {
    Login(context, user) {
      context.commit('saveLogin', user)
    },
    Out(context) {
      context.commit('outLogin')
    },
  }
}

export default modules
